package com.youchu.pattern.design.behavioral.chain;

import com.youchu.pattern.design.behavioral.chain.entity.User;
import com.youchu.pattern.design.behavioral.chain.handler.EmailRegisterHandler;
import com.youchu.pattern.design.behavioral.chain.handler.AbstractRegisterHandler;
import com.youchu.pattern.design.behavioral.chain.handler.PasswordRegisterHandler;
import com.youchu.pattern.design.behavioral.chain.handler.UserNameRegisterHandler;

// 在客户端代码中组装责任链
public class Application {
    public static void main(String[] args) {
        AbstractRegisterHandler userNameAbstractRegisterHandler = new UserNameRegisterHandler();
        AbstractRegisterHandler passwordAbstractRegisterHandler = new PasswordRegisterHandler();
        AbstractRegisterHandler emailAbstractRegisterHandler = new EmailRegisterHandler();

        // 设置责任链顺序
        userNameAbstractRegisterHandler.setNext(passwordAbstractRegisterHandler);
        passwordAbstractRegisterHandler.setNext(emailAbstractRegisterHandler);
        emailAbstractRegisterHandler.setNext(new AbstractRegisterHandler() {
            @Override
            public void handleRequest(User user) {

            }
        });

        // 创建一个用户对象
        User user = new User();
        user.setUserName("");
        user.setPassword("123456");
        user.setEmail("test@example.com");

        // 处理请求
        userNameAbstractRegisterHandler.handleRequest(user);
    }
}